package com.imooc.ecommerce.stream;

import com.alibaba.fastjson.JSON;
import com.imooc.ecommerce.vo.QinyiMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.handler.annotation.Payload;

/**
 * <p>使用默认的输入信道接收消息
 *
 * @author Yaxi.Zhang
 * @since 2022/11/15 19:31
 */
@Slf4j
@EnableBinding(Sink.class)
public class DefaultReceiveService {
    /**
     * <p>使用默认的输入信道接收消息
     */
    @StreamListener(Sink.INPUT)
    public void receiveMessage(@Payload Object payload) {
        log.info("in DefaultReceiveService consume message start");
        QinyiMessage qinyiMessage = JSON.parseObject(payload.toString(), QinyiMessage.class);
        // 消费消息
        log.info("in DefaultReceiveService consume message success: [{}]", JSON.toJSONString(qinyiMessage));
    }

}
